import React, {Component} from 'react';

class LookMsg extends Component {
  state = {
    msg: ''
  };

  leaveMsg() {
    // 拿到留言信息 传递到父组件 {msg:'',username:'',data:'',showId:2}
    let {msg} = this.state;
    let {username, sendMsg} = this.props;

    sendMsg({
      msg,
      username,
      showId: 2,
      data: new Date().toLocaleDateString() + '' + new Date().toLocaleTimeString()
    });

  }

  lookMsg() {
    this.props.changeShowId({showId: 2})
  }

  render() {
    return (
      <div>
        <h1>留言板</h1>
        用户名:{this.props.username}
        <textarea style={{display: 'block', width: '100%', height: '100px', margin: '20px'}}
                  onChange={(e) => {
                    this.setState({msg: e.target.value})
                  }}/>
        <button onClick={this.leaveMsg.bind(this)}>留言</button>
        <button onClick={this.lookMsg.bind(this)}>查看留言</button>

      </div>
    );
  }
}

export default LookMsg;
